<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<%
	String path = request.getContextPath();
%>
<html>
	 <head>
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
        <meta name="format-detection" content="telephone=no">
        <meta charset="UTF-8">

        <meta name="description" content="Violate Responsive Admin Template">
        <meta name="keywords" content="Super Admin, Admin, Template, Bootstrap">

        <title>萌校商城后台</title>
        <script src="<%=path %>/assets2/js/jquery-1.11.1.min.js"></script>
        <script src="<%=path %>/assets2/js/bootstrap.min.js"></script>
        <link href="<%=path %>/assets2/js/sweetalert/sweetalert.css" rel="stylesheet">
   		<script src="<%=path %>/assets2/js/sweetalert/sweetalert-dev.js"></script>
   		<script src="<%=path %>/assets2/js/sweetalert/sweetalert.min.js"></script>    
   		<script src="<%=path %>/assets2/js/validation/validate.min.js"></script>
        <script src="<%=path %>/assets2/js/validation/validationEngine.min.js"></script>
        <script src="<%=path %>/assets2/js/validation/messages_zh.min.js"></script>
        <script src="<%=path %>/assets2/js/jquery.form.js"></script>
        <!-- CSS -->
        <link href="<%=path %>/assets2/css/bootstrap.min.css" rel="stylesheet">
		<link href="<%=path %>/assets2/css/styles.css" rel="stylesheet">
    </head>
    <body>
    	<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
		<div class="container-fluid">
			<div class="navbar-header">
				<a class="navbar-brand" href="<%=path %>/index"><span>萌淘淘商城</span></a>
				<ul class="user-menu">
					<li class="pull-left">
						<a href="<%=path %>/index"><span class="glyphicon glyphicon-user">${user.userName }&nbsp;&nbsp;</span></a>
					</li>
					<li class="pull-right">
						<a href="<%=path %>/j_spring_security_logout"><span class="glyphicon glyphicon-log-out"></span>退出登录</a>
					</li>
				</ul>
			</div>
		</div><!-- /.container-fluid -->
	</nav>
	<div class="panel panel-default">
		<div class="panel-heading text-center">供货商信息</div>
		<div class="panel-body">
			<form role="form" class="form-validation" id="fm" action="<%=path%>/supplier/updateSupplier" method="post">
				<div class="row">
					<div class="col-md-6 col-md-offset-3">
						<div class="row">
							<div class="col-md-6 form-group">
								<label>供货商名称</label> <input type="text"
									class="input-sm validate[required] form-control"
									name="supplierName" id="supplierName">
							</div>
						</div>
						<div class="row">
							<div class="col-md-6 form-group">
								<label>联系人姓名</label> <input type="text"
									class="input-sm validate[required] form-control"
									name="linkName" id="linkName">
							</div>
							<div class="col-md-6 form-group">
								<label>联系人电话</label> <input type="text"
									class="input-sm validate[required] form-control" id="linkPhone"
									name="linkPhone" readonly="readonly" value="${user.phone }">
							</div>
						</div>
						<div class="row">
							<div class="col-md-12 form-group">
								<label>供应商地址</label>
								<input type="text"
									class="input-sm validate[required] form-control"
									name="address" id="address">
							</div>
						</div>
					</div>
				</div>
				<div class="form-group text-center">
					<br> <br>
					<button class="btn btn-lg btn-primary" id="subBtn" onclick="sub()" type="button">修改</button>
				</div>
			</form>
		</div>
	</div>
</body>
   <script type="text/javascript">
   (function(){
		if($("[class*='form-validation']")[0]) {
		    $("[class*='form-validation']").validationEngine();
		    $('body').on('click', '.validation-clear', function(e){
			e.preventDefault();
			$(this).closest('form').validationEngine('hide');
		    });
		}
	})();
   $(function(){
	  	 $.ajax({
			 type:"POST",
	         url: "<%=path %>/supplier/getSupplierInfo",
	         success: function(data,status,xhr){
	        	$('#supplierName').val(data.supplierName);
	        	$('#linkName').val(data.linkName);
	        	$('#linkPhone').val(data.linkPhone);
	        	$('#address').val(data.address);
	         }
		})
		$('#subBtn').bind('click',function(){
			sub();
    	})
   })
  function sub(){
	  if($("#fm").validationEngine("validate")){
		  $('#fm').ajaxSubmit({
				beforeSubmit:function(){
					$("#subBtn").unbind("click");
				},success:function(data) { 
				if(data.state==1){
					swal({ 
						  title: "操作成功", 
						  text: "供货商开通成功", 
						  type: "success",
						});
				}else{
					swal({ 
						  title: "操作失败", 
						  text: data.msg, 
						  type: "error",
						},function(){
							$('#subBtn').on("click",function(){
								sub();
							})
						});
				}
				}
			})
	  }
  }
  
   </script>
</html>